package com.gdsz.libbasic.utils.view

import android.view.View
import androidx.viewpager2.widget.ViewPager2


object ViewPager2Util {

    //解决viewpager2高度问题
    fun updatePagerHeightForChild(view: View?, pager: ViewPager2) {
        view?.post {
            val wMeasureSpec =
                View.MeasureSpec.makeMeasureSpec(view.width, View.MeasureSpec.EXACTLY)
            val hMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)
            view.measure(wMeasureSpec, hMeasureSpec)
            if (pager.layoutParams.height != view.measuredHeight) {
                pager.layoutParams = (pager.layoutParams)
                    .also { lp ->
                        lp.height = view.measuredHeight
                    }
            }
        }
    }

}